package com.lmf.tool;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * ControllerAdvice
 * 全局异常处理
 * 全局数据绑定
 * 全局数据预处理
 */
@ControllerAdvice
public class GlobalExceptionHandler {
    @ResponseBody
    @ExceptionHandler(CustomException.class)
    public Map<String,Object> handCustomExeption(CustomException customExeption){
        Map<String,Object> errorResultMap=new HashMap<>(16);
        errorResultMap.put("code",customExeption.getCode());
        errorResultMap.put("message",customExeption.getMessage());
        return errorResultMap;
    }
}
